import { useIntersectionObserver } from '@vueuse/core'
export const lazyPlugin = {
    install(app) {
        app.directive('img-lazy', {
            mounted(el, binding) {
                // el：绑定的img元素
                // binding：.value指令等于后边绑定表表达式的值
                // console.log(el,binding.value);
                const {stop} = useIntersectionObserver(
                    el,
                    ([{ isIntersecting }]) => {
                        // console.log(isIntersecting);
                        if (isIntersecting) {
                            el.src = binding.value
                            stop()
                            // 取消重复监听，防止资源浪费
                        }
                    }
                )
            }
        })
    }
}